﻿Public Class WelcomeControl
    Public WriteOnly Property GameName
        Set(ByVal value)
            GameNameLabel.Text = "Welcome to " & value
        End Set
    End Property
    Friend Host As Boolean = False
    Private Sub StartButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles StartButton.Click
        If Host = False Then
            MPQClient.Server.RegisterUser(MainForm.GameID, MPQClient.Username)
            StartButton.Enabled = False
            HostButton.Enabled = False
            StartButton.Text = "Waiting for host to start game"
        Else
            StartButton.Enabled = False
            StartButton.Text = "Please wait..."
            MPQClient.Server.StartQuiz(MainForm.GameID)
        End If
    End Sub

    Private Sub HostButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HostButton.Click
        If Not CType(ParentForm, MainForm).LeftPanel.Controls.ContainsKey("SelectQuizControl") Then
            Host = True
            CType(ParentForm, MainForm).LeftPanel.Controls.Add(New SelectQuizControl With {.Name = "SelectQuizControl", .Dock = DockStyle.Fill})
            CType(ParentForm, MainForm).LeftPanel.Controls("SelectQuizControl").BringToFront()
            StartButton.Enabled = False
            StartButton.Text = "Start Quiz"
            HostButton.Enabled = False
        Else
            With CType(CType(ParentForm, MainForm).LeftPanel.Controls("SelectQuizControl"), SelectQuizControl)
                MPQClient.Server.RegisterHost(MainForm.GameID, MPQClient.Username, .ListBox1.SelectedItem)
                StartButton.Text = "Start Quiz"
                HostButton.Enabled = False
                StartButton.Enabled = True
                .Start()
            End With
        End If
    End Sub

    Private Sub WelcomeControl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If My.Application.CommandLineArgs.Contains("/DEBUG") Then
            StartButton.PerformClick()
        End If
        If FirstPlay Then
            TutorialControl1.ShowAndMoveOn()
        End If
    End Sub

    Private Sub SecondTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SecondTimer.Tick
        Try
            MPQClient.Server.GetGameDetails(MainForm.GameID)
        Catch
        End Try
    End Sub
End Class
